package com.sqx.modules.labelType.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.modules.labelType.entity.LabelType;
import com.sqx.modules.labelType.dao.LabelTypeDao;
import com.sqx.modules.labelType.service.LabelTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.sqx.common.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.time.LocalDateTime;

/**
 * 分类标签 服务实现类
 *
 * @author wuChang
 * @since 2024-05-29
 */
@Service
public class LabelTypeServiceImp extends ServiceImpl<LabelTypeDao, LabelType> implements LabelTypeService {


    @Override
    public Result saveLabelType(LabelType labelType) {
        if (labelType.getLabelId() != null) {
            return Result.upStatus(baseMapper.updateById(labelType));
        } else {
            labelType.setCreateTime(LocalDateTime.now());
            return Result.upStatus(baseMapper.insert(labelType));
        }
    }

    @Override
    public IPage<LabelType> getLabelTypeList(Integer page, Integer limit, LabelType labelType) {
        Page<LabelType> pages;
//        if (page != null && limit != null) {
//            pages = new Page<>(page, limit);
//        } else {
            pages = new Page<>();
            pages.setSize(-1);
//        }
        return baseMapper.selectPage(pages, new QueryWrapper<>(labelType)
                .eq(labelType.getIsRecovery() == null,"is_recovery", 0)
                .orderByAsc("sort"));
    }

    @Override
    public IPage<LabelType> getLabelTypeList1(Integer page, Integer limit, LabelType labelType) {
        Page<LabelType> pages;
        if (page != null && limit != null) {
            pages = new Page<>(page, limit);
        } else {
            pages = new Page<>();
            pages.setSize(-1);
        }
        return baseMapper.selectPageByType(pages, labelType);
    }
}
